import request from '@/utils/request'

// 查询数据库列表
export function listDatabase(query) {
  return request({
    url: '/system/dbmanagement/list',
    method: 'get',
    params: query
  })
}

// 查询数据库详细
export function getDatabase(dbId) {
  return request({
    url: '/system/dbmanagement/' + dbId,
    method: 'get'
  })
}

// 新增数据库
export function addDatabase(data) {
  return request({
    url: '/system/dbmanagement',
    method: 'post',
    data: data
  })
}

// 修改数据库
export function updateDatabase(data) {
  return request({
    url: '/system/dbmanagement',
    method: 'put',
    data: data
  })
}

// 删除数据库
export function delDatabase(dbId) {
  return request({
    url: '/system/dbmanagement/' + dbId,
    method: 'delete'
  })
}

// 测试数据库连接
export function testDatabaseConnection(dbId) {
  return request({
    url: '/system/dbmanagement/test/' + dbId,
    method: 'get'
  })
}

// 获取数据库表列表
export function listDatabaseTables(dbId) {
  return request({
    url: '/system/dbmanagement/tables/' + dbId,
    method: 'get'
  })
}

// 备份数据库
export function backupDatabase(data) {
  return request({
    url: '/system/dbmanagement/backup',
    method: 'post',
    data: data
  })
}

// 还原数据库
export function restoreDatabase(data) {
  return request({
    url: '/system/dbmanagement/restore',
    method: 'post',
    data: data
  })
}

// 获取备份历史
export function getBackupHistory(dbId) {
  return request({
    url: '/system/dbmanagement/backupHistory/' + dbId,
    method: 'get'
  })
} 